#include "timedialog.h"
#include "ui_timedialog.h"
#include "QHBoxLayout"
#include "QTime"

TimeDialog::TimeDialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::TimeDialog)
{
    ui->setupUi(this);

    label = new QLabel(this);
    label->setFrameStyle(QFrame::Panel|QFrame::Sunken);
    label->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
    QFont font;
    font.setPointSize(20);
    label->setFont(font);
    btn = new QPushButton("刷新时间", this);
    btn->setFont(font);

    QHBoxLayout* layout = new QHBoxLayout();
    layout->addWidget(label);
    layout->addWidget(btn);
    setLayout(layout);

    connect(btn, SIGNAL(clicked(void)), this, SLOT(getTime(void)));
    connect(this, SIGNAL(timeSignal(QString)), label, SLOT(setText(QString)));
}

TimeDialog::~TimeDialog()
{
    delete ui;
}

void TimeDialog::getTime()
{
    QTime time = QTime::currentTime();
    QString str = time.toString("hh:mm:ss");
//    label->setText(str);
    emit timeSignal(str);
}
